from fractions import Fraction
def matrix(array_list):
    if len(array_list) == 16:
        print('==============')
        ls = array_list
        #初始化
        s = 0
        for i in ls: 
            ls[s] = Fraction(i)
            s += 1
        print('题目为：')
        print_ar(ls)
        mp1 = ls[4]/ls[0]
        mp2 = ls[8]/ls[0]
        mp3 = ls[12]/ls[0]
        ls=e(ls,2,1,mp1)
        ls=e(ls,3,1,mp2)
        ls=e(ls,4,1,mp3)
        ms = '第一步：r2 - {}r1,r3 - {}r1,r4 - {}r1'.format(mp1,mp2,mp3)
        print(ms)
        print_ar(ls)
        mp1 = ls[9]/ls[5]
        mp2 = ls[13]/ls[5]
        ms = '第二步：r3 - {}r2,r4 - {}r2'.format(mp1,mp2)
        ls=e(ls,3,2,mp1)
        ls=e(ls,4,2,mp2)
        print(ms)
        print_ar(ls)
        mp1 = ls[14]/ls[10]
        ms = '第三步：r4 - {}r3'.format(mp1)
        ls=e(ls,4,3,mp1)
        print(ms)
        print_ar(ls)
        return ''
def e(list,ra,rb,mp):
    if mp==0:
        return list
    r1 = list[0:4]
    r2 = list[4:8]
    r3 = list[8:12]
    r4 = list[12:16]
    if ra == 1:
        ra1 = r1
    elif ra == 2:
        ra1 = r2
    elif ra == 3:
        ra1 = r3
    elif ra == 4:
        ra1 = r4
    if rb == 1:
        rb1 = r1
    elif rb == 2:
        rb1 = r2
    elif rb == 3:
        rb1 = r3
    elif rb == 4:
        rb1 = r4
    ra1[0] = ra1[0]-rb1[0]*mp
    ra1[1] = ra1[1]-rb1[1]*mp
    ra1[2] = ra1[2]-rb1[2]*mp
    ra1[3] = ra1[3]-rb1[3]*mp
    if ra == 1:
        r1 == ra1
    elif ra == 2:
        r2 = ra1
    elif ra == 3:
        r3 = ra1
    elif ra == 4:
        r4 = ra1
    if rb == 1:
        r1 = rb1
    elif rb == 2:
        r2 = rb1
    elif rb == 3:
        r3 = rb1
    elif rb == 4:
        r4 = rb1
    list = r1+r2+r3+r4
    return list
def print_ar(list1):
    s = 0 
    print('===============')
    print('矩阵：')
    for i in list1:
        if s == 3 or s == 7 or s == 11 or s == 15:
            print(list1[s])
        else:
            print(list1[s],end=' ')
        s += 1
    print('===============')
    return ''
print(matrix([1,-3,0,-1,-2,1,3,0,0,2,2,4,3,4,-1,9]))